package com.xbongbong.saas.enums.business;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.enums.WorkReportEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 工作报告类型枚举类
 *
 * @author feng.zheng
 * @version v1.0
 * @date 2019/1/14 15:37
 * @since v1.0
 */
@Getter
public enum WorkReportTypeEnum {
    // 工作报告类型
    DAILY(WorkReportEnum.WORKREPORT_DAILY.getI18nName(), 1, XbbRefTypeEnum.WORKREPORT_DAILY.getCode()),
    WEEKLY(WorkReportEnum.WORKREPORT_WEEKLY.getI18nName(), 2, XbbRefTypeEnum.WORKREPORT_WEEKLY.getCode()),
    MONTHLY(WorkReportEnum.WORKREPORT_MONTHLY.getI18nName(), 3, XbbRefTypeEnum.WORKREPORT_MONTHLY.getCode()),;

    /**
     * 报告类型名称
     */
    private String name;

    /**
     * 报告类型
     */
    private Integer type;

    /**
     * businessType
     */
    private int businessType;

    WorkReportTypeEnum(String name, Integer type, int businessType) {
        this.name = name;
        this.type = type;
        this.businessType = businessType;
    }

    public static WorkReportTypeEnum getByType(Integer type){
        for(WorkReportTypeEnum workReportTypeEnum: values()) {
            if(workReportTypeEnum.getType().equals(type)) {
                return workReportTypeEnum;
            }
        }
        return null;
    }

    public static WorkReportTypeEnum getByBusinessType(Integer businessType){
        for(WorkReportTypeEnum workReportTypeEnum: values()) {
            if(Objects.equals(workReportTypeEnum.getBusinessType(), businessType)) {
                return workReportTypeEnum;
            }
        }
        return null;
    }

    public static WorkReportTypeEnum getByName(String name){
        for(WorkReportTypeEnum workReportTypeEnum: values()) {
            if(workReportTypeEnum.getName().equals(name)) {
                return workReportTypeEnum;
            }
        }
        return null;
    }

    public static WorkReportTypeEnum getByTypeWithDefault(Integer type){
        for(WorkReportTypeEnum workReportTypeEnum: values()) {
            if(Objects.equals(workReportTypeEnum.getType(), type)) {
                return workReportTypeEnum;
            }
        }
        return DAILY;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
